import { Api, BASE_URL } from '../script/Api';
import { defineStore } from 'pinia';

const store = defineStore('user', {
  state() {
    return {
      isLogin: false,
      userInfo: {
        tbUser: {},
        tbUserInfo: {},
        tbRole: {},
        exInfo: {},
        logo: '',
      },
    };
  },
  actions: {
    queryUser(cb) {
      let instance = this;
      Api.get('/auth', {}, (data) => {
        if (data.success) {
          instance.isLogin = true;
          instance.userInfo = data.data;
          instance.userInfo.logo = BASE_URL + '/user/logo';
        } else {
          instance.isLogin = false;
          instance.userInfo = {
            tbUser: {},
            tbUserInfo: {},
            tbRole: {},
            exInfo: {},
            logo: '',
          };
        }
        cb?.(data.success);
      });
    },
  },
});

export default store;
